package com.tedu.controller;

import com.tedu.pojo.User;
import com.tedu.service.UserService;
import com.tedu.util.JsonResult;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * <p>
 *
 * </p>
 *
 * @author Song
 * @since 2020/11/23
 */
@RestController
@Slf4j
public class UserController {

    @Autowired
    private UserService userService;

    @RequestMapping("/{userId}")
    public JsonResult<User> getUserById(@PathVariable Integer userId) {
        return JsonResult.ok().data(userService.getUser(userId));
    }

    @GetMapping("/{userId}/score")
    public JsonResult<?> score(@PathVariable Integer userId, Integer score) {

        userService.addScore(userId, score);
        return JsonResult.ok().msg("增加用户积分成功");
    }
}
